<?php

namespace App\Http\Controllers\System;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use App\Common\Utils\JsonResponse;
use Illuminate\Http\Request;

class ScaleController extends Controller
{
    /** @var \App\Services\System\LogService $logService */
    private $logService;
    /** @var \App\Services\System\ScaleService $scaleService */
    private $scaleService;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
        $this->middleware('auth');
        $this->logService = app('logService');
        $this->scaleService = app('scaleService');
    }


    /**
     * @Description: 获取列表
     * @Author: kzj
     * @datetime: 2022-11-25
     */
    public function list(Request $request)
    {
        try
        {
            $result = $this->scaleService->list($request->all());
            // $this->logService->log('5','考核量表数据查看', "考核量表数据查看");
            return JsonResponse::get($result['data'], TRUE, $result['total'], $result['per_page']);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }

    /**
     * @Description: 新增量表
     * @Author: kzj
     * @datetime: 2022-11-25
     */
    public function add(Request $request)
    {
        try
        {
            $result = $this->scaleService->add($request->all());
            // $this->logService->log('5','考核量表数据创建', "考核量表数据创建");
            return JsonResponse::success($result);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }

    /**
     * @Description: 量表复制
     * @Author: kzj
     * @datetime: 2022-11-25
     */
    public function copy(Request $request)
    {
        try
        {
            $result = $this->scaleService->copy($request->all());
            // $this->logService->log('5','考核量表数据复制', "考核量表数据复制");
            return JsonResponse::success($result);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }

    /**
     * @Description: 获取单条数据
     * @Author: kzj
     * @datetime: 2022-11-25
     */
    public function getOne(Request $request)
    {
        try
        {
            $result = $this->scaleService->getOne($request->all());
            return JsonResponse::success($result);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }

    /**
     * @Description: 编辑量表
     * @Author: kzj
     * @datetime: 2022-11-25
     */
    public function edit(Request $request)
    {
        try
        {
            $this->scaleService->edit($request->all());
            // $this->logService->log('5','考核量表数据编辑', "考核量表数据编辑");
            return JsonResponse::operate();
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }
    
    /**
     * @Description: 量表删除
     * @Author: kzj
     * @datetime: 2022-11-27
     */
    public function del(Request $request)
    {
        try
        {
            $result = $this->scaleService->del($request->all());
            // $this->logService->log('5','考核量表数据删除', "考核量表数据删除");
            return JsonResponse::success($result);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }
    
    /**
     * @Description: 量表考核内容新增
     * @Author: kzj
     * @datetime: 2022-11-26
     */
    public function addDetail(Request $request)
    {
        try
        {
            $result = $this->scaleService->addDetail($request->all());
            // $this->logService->log('5','考核量表考核内容新增', "考核量表考核内容新增");
            return JsonResponse::success($result);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }
    
    /**
     * @Description: 量表考核行内容新增
     * @Author: kzj
     * @datetime: 2022-11-26
     */
    public function addRowDetail(Request $request)
    {
        try
        {
            $result = $this->scaleService->addRowDetail($request->all());
            // $this->logService->log('5','考核量表行内容新增', "考核量表行内容新增");
            return JsonResponse::success($result);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }
    
    /**
     * @Description: 量表考核内容编辑
     * @Author: kzj
     * @datetime: 2022-11-26
     */
    public function editDetail(Request $request)
    {
        try
        {
            $result = $this->scaleService->editDetail($request->all());
            // $this->logService->log('5','量表考核内容编辑', "量表考核内容编辑");
            return JsonResponse::success($result);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }
    
    /**
     * @Description: 量表考核内容删除
     * @Author: kzj
     * @datetime: 2022-11-26
     */
    public function delDetail(Request $request)
    {
        try
        {
            $result = $this->scaleService->delDetail($request->all());
            // $this->logService->log('5','量表考核内容删除', "量表考核内容删除");
            return JsonResponse::success($result);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }
    
    /**
     * @Description: 单个量表考核内容修改
     * @Author: kzj
     * @datetime: 2022-11-27
     */
    public function updateDetail(Request $request)
    {
        try
        {
            $result = $this->scaleService->updateDetail($request->all());
            return JsonResponse::success($result);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }
    
    /**
     * @Description: 考核量表下拉选择数据
     * @Author: kzj
     * @datetime: 2022-11-27
     */
    public function selectList(Request $request)
    {
        try
        {
            $result = $this->scaleService->selectList($request->all());
            return JsonResponse::success($result);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }
    
}
